package org.example.quartz.task;

import cn.hutool.db.Entity;
import cn.hutool.db.Session;
import cn.hutool.extra.spring.SpringUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.example.quartz.service.LogService;
import org.example.quartz.service.OrgService;
import org.example.quartz.service.UtilService;
import org.example.quartz.util.DataSourceUtil;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.PersistJobDataAfterExecution;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Component
// 再Job被执行结束后，将会更新JobDataMap，这样下次Job执行后悔使用新的值而不是初始值
@PersistJobDataAfterExecution
// 同一时间将只有一个Job实例被执行，为了避免并发问题导致数据紊乱，建议这两个注解一起使用
@DisallowConcurrentExecution
public class GLTOMIDQuartz implements QuartzTaskJob {

    Map<String, Object> gsMap = DataSourceUtil.getGS();
    //全局接口配置
    String IP = (String) gsMap.get("IP");
    String PORT = (String) gsMap.get("PORT");
    String ECC = (String) gsMap.get("ECC");
    String Bearer = (String) gsMap.get("Bearer");

    //日志
    LogService loginfo = SpringUtil.getBean(LogService.class);
    //orgService
    OrgService orgService = SpringUtil.getBean(OrgService.class);
    //orgService
    UtilService utilService = SpringUtil.getBean(UtilService.class);
    /**
     * 凭证接口
     * 接口地址：GSCloud文档3.13
     * http://ip:port/api/jg/fiaccdata/v1.0/fiaccinterface/insertPzMidTable
     **/
    @SneakyThrows
    @Override
    public void execute(JobExecutionContext context) {
        //传入变量 lastTime 最后抓取时间
        //链接BIP数据库，查询出需要同步的数据，根据TS时间进行判断。
        //TS从中间库表获取到最后一次更新时间，根据此时间进行增量查询推送；
        //中间库日志表记录推送日志，成功、失败、返回信息等（备查）
        //中间库记录最后推送数据的时间，根据时间进行下次查询的条件；
        String methodName = "GLTOMIDQuartz";
        JdbcTemplate jdbcTemplate = SpringUtil.getBean(JdbcTemplate.class);
        //1、查询时间
        String ts = utilService.getTs(methodName, jdbcTemplate);
        String orgStr = utilService.getGSOrgStr(jdbcTemplate);
        //2、根据时间查询数据集 (停用和删除的过滤掉，暂不考虑，线下处理)
        String selectSQL = "--辅助核算 GL_DOCFREE1--凭证分录 GL_DETAIL--凭证表 GL_VOUCHER--财务核算账簿 org_accountingbook\n" +
                "SELECT--ID\\tID\\tVARCHAR2 (36)\\t否\\t主键\n" +
                "GL.PK_DETAIL AS ID,\n" +
                "--ORGCODE\\t账簿编号\\tVARCHAR2 (100)\\t否\\t\n" +
                "book.code AS ORGCODE,\n" +
                "--ACCDOCCODE\\t凭证编号\\tVARCHAR2 (100)\\t否\\t格式：记000004\n" +
                "VT.SHORTNAME || GLV.NUM AS ACCDOCCODE,\n" +
                "--ACCDOCDATE\\t凭证日期\\tVARCHAR2 (8)\\t否\\t20240405\n" +
                "GLV.PREPAREDDATE AS ACCDOCDATE,\n" +
                "--ACCDOCTYPECODE\\t凭证类型编号\\tVARCHAR2 (100)\\t否\\t\n" +
                "VT.CODE AS ACCDOCTYPECODE,\n" +
                "--PERIODCODE\\t会计期间编号\\tVARCHAR2 (2)\\t否\\t如01\n" +
                "GLV.PERIOD AS PERIODCODE,\n" +
                "--NUMBEROFATTCH\\t附件张数\\tINT4\\t否\\t\n" +
                "GLV.ATTACHMENT AS NUMBEROFATTCH,\n" +
                "--YEAR\\t年度\\tVARCHAR2 (4)\\t否\\t如2024\n" +
                "GLV.YEAR AS YEAR,\n" +
                "--MAKERCODE\\t制单人编号\\tVARCHAR2 (100)\\t否\\t\n" +
                "sm.user_code AS MAKERCODE,\n" +
                "--OPERATORCODE\\t经办人编号\\tVARCHAR2 (100)\\t是\\t默认空\n" +
                "'' AS OPERATORCODE,\n" +
                "--SECRETLEVEL\\t密级\\tVARCHAR2 (100)\\t是\\t默认空\n" +
                "'' AS SECRETLEVEL,\n" +
                "--APPROVERCODE\\t批准人编号\\tVARCHAR2 (100)\\t是\\t默认空\n" +
                "'' AS APPROVERCODE,\n" +
                "--AUDITORCODE\\t审核人编号\\tVARCHAR2 (100)\\t是\\t操作用户编号\n" +
                "'' AS AUDITORCODE,\n" +
                "--BOOKERCODE\\t记账人编号\\tVARCHAR2 (100)\\t是\\t操作用户编号\n" +
                "'' AS BOOKERCODE,\n" +
                "--CASHIERCODE\\t出纳编号\\tVARCHAR2 (100)\\t是\\t操作用户编号\n" +
                "'' AS CASHIERCODE,\n" +
                "--ACCMANAGERCODE\\t会计主管编号\\tVARCHAR2 (100)\\t是\\t操作用户编号\n" +
                "'' AS ACCMANAGERCODE,\n" +
                "--ISAUDIT\\t是否审核\\tVARCHAR2 (1)\\t是\\t1是，0否，默认空\n" +
                "'' AS ISAUDIT,\n" +
                "--ISBOOK\\t是否记账\\tVARCHAR2 (1)\\t是\\t1是，0否，默认空\n" +
                "'' AS ISBOOK,\n" +
                "--ISVOID\\t是否作废\\tVARCHAR2 (1)\\t是\\t1是，0否，默认空\n" +
                "'' AS ISVOID,\n" +
                "--ISAPPROVED\\t是否批准\\tVARCHAR2 (1)\\t是\\t1是，0否，默认空\n" +
                "'' AS ISAPPROVED,\n" +
                "--EXTERNALDOC\\t下级单位凭证编号\\tVARCHAR2 (100)\\t是\\t下级单位凭证编号\n" +
                "'' AS EXTERNALDOC,\n" +
                "--ISREADYONLY\\t只读标志\\tVARCHAR2 (1)\\t是\\t1是，0否\n" +
                "'' AS ISREADYONLY,\n" +
                "--CREATOR\\t创建人编号\\tVARCHAR2 (100)\\t否\\t操作用户编号\n" +
                "sm.user_code AS CREATOR,\n" +
                "--CREATETIME\\t创建时间\\tTIMESTAMP(6)\\t否\\t2024-04-07 13:28:35\n" +
                "GLV.PREPAREDDATE AS CREATETIME,\n" +
                "--LASTMODIFIER\\t最后修改人编号\\tVARCHAR2 (100)\\t否\\t操作用户编号\n" +
                "'' AS LASTMODIFIER,\n" +
                "--LASTMODIFIEDTIME\\t最后修改时间\\tTIMESTAMP(6)\\t否\\t2024-04-07 13:28:35\n" +
                "'' AS LASTMODIFIEDTIME,\n" +
                "--SUMMARY\\t摘要\\tVARCHAR2 (1000)\\t否\\t\n" +
                "GL.EXPLANATION AS SUMMARY,\n" +
                "--ACCENTRYCODE\\t凭证分录编号\\tVARCHAR2 (100)\\t否\\t00043\n" +
                "LPAD( GL.DETAILINDEX, 5, '0' ) AS ACCENTRYCODE,\n" +
                "--ACCTITLECODE\\t科目编号\\tVARCHAR2 (100)\\t否\\t\n" +
                "GL.ACCOUNTCODE AS ACCTITLECODE,\n" +
                "--DOCENTRYAMOUNT\\t凭证分录金额\\tNUMERIC(28,8)\\t否\\t\n" +
                "( CASE WHEN GL.DIRECTION = 'D' THEN GL.DEBITAMOUNT ELSE GL.CREDITAMOUNT END ) AS DOCENTRYAMOUNT,\n" +
                "--LENDINGDIRECTION\\t记账方向\\tVARCHAR2 (1)\\t否\\t1借，2贷\n" +
                "( CASE WHEN GL.DIRECTION = 'D' THEN '借' ELSE '贷' END ) AS LENDINGDIRECTION,\n" +
                "--DEPTID\\t核算部门编号\\tVARCHAR2 (100)\\t是\\t0093\n" +
                "'' AS DEPTID,\n" +
                "--RELATEDORGID\\t往来单位编号\\tVARCHAR2 (100)\\t是\\t0934\n" +
                "'' AS RELATEDORGID,\n" +
                "--ACCEMPLOYEEID\\t核算人员编号\\tVARCHAR2 (100)\\t是\\t0921\n" +
                "'' AS ACCEMPLOYEEID,\n" +
                "--FOREIGNCURRENCYID\\t币种编号\\tVARCHAR2 (100)\\t否\\t\n" +
                "BC.CODE AS FOREIGNCURRENCYID,\n" +
                "--QUANTITY\\t数量\\tNUMERIC(28,8)\\t否\\t0\n" +
                "( CASE WHEN GL.DIRECTION = 'D' THEN GL.DEBITQUANTITY ELSE GL.CREDITQUANTITY END ) AS QUANTITY,\n" +
                "--UNITPRICE\\t单价\\tNUMERIC(28,8)\\t否\\t0\n" +
                "GL.PRICE AS UNITPRICE,\n" +
                "--FOREIGNCURRENCY\\t辅助外币金额\\tNUMERIC(28,8)\\t否\\t\n" +
                "( CASE WHEN GL.DIRECTION = 'D' THEN GL.DEBITAMOUNT ELSE GL.CREDITAMOUNT END ) AS FOREIGNCURRENCY,\n" +
                "--EXCHANGERATE\\t汇率\\tNUMERIC(28,8)\\t否\\t\n" +
                "'1' AS EXCHANGERATE,\n" +
                "--ANCILLARYAMOUNT\\t辅助金额\\tNUMERIC(28,8)\\t否\\t\n" +
                "( CASE WHEN GL.DIRECTION = 'D' THEN GL.DEBITAMOUNT ELSE GL.CREDITAMOUNT END ) AS ANCILLARYAMOUNT,\n" +
                "--BIZDATE\\t业务日期\\tVARCHAR2 (8)\\t是\\t如20240122\n" +
                "'' AS BIZDATE,\n" +
                "--BIZCODE\\t业务号\\tVARCHAR2 (100)\\t是\\t\n" +
                "'' AS BIZCODE,\n" +
                "--OPERATOR\\t经办人\\tVARCHAR2 (100)\\t是\\t操作用户编号\n" +
                "'' AS OPERATOR,\n" +
                "--SJ01~SJ05\\t自定义数值字段01~自定义数值字段05\\tNUMERIC(28,8)\\t是\\t\n" +
                "'' AS SJ,\n" +
                "--SM01~SM10\\t自定义文本字段01~自定义文本字段10\\tVARCHAR2 (100)\\t是\\t\n" +
                "'' AS SM,\n" +
                "--SETTLEMENT\\t结算方式\\tVARCHAR2 (36)\\t是\\t\n" +
                "BB.NAME AS SETTLEMENT,\n" +
                "--SETTLEMENTNUMBER\\t结算号\\tVARCHAR2 (100)\\t是\\t\n" +
                "'' AS SETTLEMENTNUMBER,\n" +
                "--APPLICATION\\t用途\\tVARCHAR2 (1000)\\t是\\t\n" +
                "'' AS APPLICATION,\n" +
                "--SETTLEMENTDATE\\t结算日期\\tVARCHAR2 (8)\\t是\\t如20240122\n" +
                "'' AS SETTLEMENTDATE,\n" +
                "--CASHPROJECT\\t现金项目\\tVARCHAR2 (100)\\t是\\t\n" +
                "'' AS CASHPROJECT,\n" +
                "--SPECATEID51~ SPECATEID99\\t核算项目51~核算项目99\\tVARCHAR2 (100)\\t是\\t\n" +
                "'' AS SPECATEID,\n" +
                "--BILLNUMBER\\t票据号\\tVARCHAR2 (100)\\t是\\t\n" +
                "'' AS BILLNUMBER,\n" +
                "--DATASTAUS\\t单据状态\\tCHAR(1)\\t否\\t0表示新增，1表示修改，2表示删除\n" +
                "(CASE WHEN GL.DR = 1 THEN '2' ELSE '0' END) AS DATASTAUS,\n" +
                "--ISIMPORTED\\t是否已导入备查实例\\tCHAR\\t否\\t0表示否，1表示是，2表示导入失败\n" +
                "'0' AS ISIMPORTED,\n" +
                "--FAILREASON\\t失败原因\\tVARCHAR2(500)\\t是\\t\n" +
                "'' AS FAILREASON,\n" +
                "--BATCHNO\\t批次号\\tVARCHAR2(200)\\t否\\t账簿编号年月日时分秒拼接，账簿编号20220908010502\n" +
                "'' AS BATCHNO,\n" +
                "--REFERENCEID\\tGSCLOUD凭证ID\\tVARCHAR2 (36)\\t是\\t如果DATASTAUS字段是修改或删除，该字段必填\n" +
                "'' AS REFERENCEID,\n" +
                "--LYPZID\\t下级单位凭证唯一标识\\tVARCHAR2 (100)\\t否\\t\n" +
                "GL.PK_VOUCHER AS LYPZID,\n" +
                "--FZCODE\\t辅助分录编号\\tVARCHAR2(50)\\t\\t如果一个凭证科目分录最多只会有一行辅助数据，该值默认为00001，如果多条按使用流水号即可（00001、00002）。\n" +
                "'00001' AS FZCODE,\n" +
                "GL.TS AS TS,\n" +
                "GL.ASSID AS ASSID \n" +
                "FROM\n" +
                "\tGL_DETAIL GL\n" +
                "\tLEFT JOIN org_accountingbook book ON gl.pk_accountingbook = book.PK_ACCOUNTINGBOOK\n" +
                "\tLEFT JOIN ORG_ORGS ORG ON GL.PK_ORG = ORG.PK_ORG\n" +
                "\tLEFT JOIN GL_VOUCHER GLV ON GL.PK_VOUCHER = GLV.PK_VOUCHER\n" +
                "\tLEFT JOIN sm_user sm ON glv.pk_prepared = sm.cuserid\n" +
                "\tLEFT JOIN BD_VOUCHERTYPE VT ON GLV.PK_VOUCHERTYPE = VT.PK_VOUCHERTYPE\n" +
                "\tLEFT JOIN BD_CURRTYPE BC ON GL.PK_CURRTYPE = BC.PK_CURRTYPE\n" +
                "\tLEFT JOIN BD_BALATYPE BB ON GL.CHECKSTYLE = BB.PK_BALATYPE --LEFT JOIN BD_CASHFLOW BF ON GL.CASHFLOWITEM = BF.PK_CASHFLOW\n" +
                "WHERE\n" +
                "\tORG.CODE IN ("+orgStr+")" +
                " AND " +
                " GL.TS >'"+ts+"'";
        //查询数据，根据数据结果推送给GS浪潮
        Session oracleSession = DataSourceUtil.getOracleSession();
        List<Entity> query = oracleSession.query(selectSQL);
        //将查询的数据按照凭证号、会计期间、年份进行分组（单张凭证推送中间库）
        Map<String, List<Entity>> voucherid = query.stream().collect(Collectors.groupingBy(i -> i.get("ACCDOCCODE")+","+i.get("PERIODCODE")+","+i.get("YEAR")));
        for (Map.Entry<String, List<Entity>> objectListEntry : voucherid.entrySet()) {
            String insertSQL = "";
            String logTS = "";
            String voucherCode = "";
            List<Entity> value = objectListEntry.getValue();
            if(value.size()>0){
                insertSQL = "INSERT INTO gl_detail (\n" +
                        "ID,\n" +
                        "ORGCODE,\n" +
                        "ACCDOCCODE,\n" +
                        "ACCDOCDATE,\n" +
                        "ACCDOCTYPECODE,\n" +
                        "PERIODCODE,\n" +
                        "NUMBEROFATTCH,\n" +
                        "YEAR,\n" +
                        "MAKERCODE,\n" +
                        "OPERATORCODE,\n" +
                        "SECRETLEVEL,\n" +
                        "APPROVERCODE,\n" +
                        "AUDITORCODE,\n" +
                        "BOOKERCODE,\n" +
                        "CASHIERCODE,\n" +
                        "ACCMANAGERCODE,\n" +
                        "ISAUDIT,\n" +
                        "ISBOOK,\n" +
                        "ISVOID,\n" +
                        "ISAPPROVED,\n" +
                        "EXTERNALDOC,\n" +
                        "ISREADYONLY,\n" +
                        "CREATOR,\n" +
                        "CREATETIME,\n" +
                        "LASTMODIFIER,\n" +
                        "LASTMODIFIEDTIME,\n" +
                        "SUMMARY,\n" +
                        "ACCENTRYCODE,\n" +
                        "ACCTITLECODE,\n" +
                        "DOCENTRYAMOUNT,\n" +
                        "LENDINGDIRECTION,\n" +
                        "DEPTID,\n" +
                        "RELATEDORGID,\n" +
                        "ACCEMPLOYEEID,\n" +
                        "FOREIGNCURRENCYID,\n" +
                        "QUANTITY,\n" +
                        "UNITPRICE,\n" +
                        "FOREIGNCURRENCY,\n" +
                        "EXCHANGERATE,\n" +
                        "ANCILLARYAMOUNT,\n" +
                        "BIZDATE,\n" +
                        "BIZCODE,\n" +
                        "OPERATOR,\n" +
                        "SJ,\n" +
                        "SM,\n" +
                        "SETTLEMENT,\n" +
                        "SETTLEMENTNUMBER,\n" +
                        "APPLICATION,\n" +
                        "SETTLEMENTDATE,\n" +
                        "CASHPROJECT,\n" +
                        "SPECATEID,\n" +
                        "BILLNUMBER,\n" +
                        "DATASTAUS,\n" +
                        "ISIMPORTED,\n" +
                        "FAILREASON,\n" +
                        "BATCHNO,\n" +
                        "REFERENCEID,\n" +
                        "LYPZID,\n" +
                        "FZCODE,\n" +
                        "TS," +
                        "ASSID," +
                        "YYZTCODE\n" +
                        ")\n" +
                        "VALUES\n" ;

                    for (Map<String, Object> gSmap : value) {
                        String DATASTAUS = (String) gSmap.get("DATASTAUS");
                        String REFERENCEID = "";
                        //现将数据存入中间库GL_DETAIL表中；  判断数据是新增还是修改；根据ID判断在中间库是否存在啊，如存在，是修改、不存在是新增。如果存在，查询回执的gsID是否有值，有值给当前数据赋值REFERENCEID
                        String selectAddOrUpdate = "select REFERENCEID FROM GL_DETAIL WHERE ID = '"+gSmap.get("ID")+"'";
                        List<Map<String, Object>> maps = jdbcTemplate.queryForList(selectAddOrUpdate);
                        //如果是删除，就不用校验是否
                        if(DATASTAUS.equals("0")){
                            //如果maps查询有值，则是修改，同步给REFERENCEID 赋值，如果 REFERENCEID为空，则赋值空。
                            if(maps.size()>0){
                                REFERENCEID = (String) maps.get(0).get("REFERENCEID");
                            }
                        }else{
                            //如果maps查询有值，则是修改，同步给REFERENCEID 赋值，如果 REFERENCEID为空，则赋值空。
                            if(maps.size()>0){
                                DATASTAUS = "1";
                                REFERENCEID = (String) maps.get(0).get("REFERENCEID");
                            }
                        }
                        insertSQL += "('"+ gSmap.get("ID")+"', \n" +
                                "'"+ gSmap.get("ORGCODE")+"', \n" +
                                "'"+ gSmap.get("ACCDOCCODE")+"', \n" +
                                "'"+ gSmap.get("ACCDOCDATE")+"', \n" +
                                "'"+ gSmap.get("ACCDOCTYPECODE")+"', \n" +
                                "'"+ gSmap.get("PERIODCODE")+"', \n" +
                                "'"+ gSmap.get("NUMBEROFATTCH")+"', \n" +
                                "'"+ gSmap.get("YEAR")+"', \n" +
                                "'"+ gSmap.get("MAKERCODE")+"', \n" +
                                "'"+ gSmap.get("OPERATORCODE")+"', \n" +
                                "'"+ gSmap.get("SECRETLEVEL")+"', \n" +
                                "'"+ gSmap.get("APPROVERCODE")+"', \n" +
                                "'"+ gSmap.get("AUDITORCODE")+"', \n" +
                                "'"+ gSmap.get("BOOKERCODE")+"', \n" +
                                "'"+ gSmap.get("CASHIERCODE")+"', \n" +
                                "'"+ gSmap.get("ACCMANAGERCODE")+"', \n" +
                                "'"+ gSmap.get("ISAUDIT")+"', \n" +
                                "'"+ gSmap.get("ISBOOK")+"', \n" +
                                "'"+ gSmap.get("ISVOID")+"', \n" +
                                "'"+ gSmap.get("ISAPPROVED")+"', \n" +
                                "'"+ gSmap.get("EXTERNALDOC")+"', \n" +
                                "'"+ gSmap.get("ISREADYONLY")+"', \n" +
                                "'"+ gSmap.get("CREATOR")+"', \n" +
                                "'"+ gSmap.get("CREATETIME")+"', \n" +
                                "'"+ gSmap.get("LASTMODIFIER")+"', \n" +
                                "'"+ gSmap.get("LASTMODIFIEDTIME")+"', \n" +
                                "'"+ gSmap.get("SUMMARY")+"', \n" +
                                "'"+ gSmap.get("ACCENTRYCODE")+"', \n" +
                                "'"+ gSmap.get("ACCTITLECODE")+"', \n" +
                                "'"+ gSmap.get("DOCENTRYAMOUNT")+"', \n" +
                                "'"+ gSmap.get("LENDINGDIRECTION")+"', \n" +
                                "'"+ gSmap.get("DEPTID")+"', \n" +
                                "'"+ gSmap.get("RELATEDORGID")+"', \n" +
                                "'"+ gSmap.get("ACCEMPLOYEEID")+"', \n" +
                                "'"+ gSmap.get("FOREIGNCURRENCYID")+"', \n" +
                                "'"+ gSmap.get("QUANTITY")+"', \n" +
                                "'"+ gSmap.get("UNITPRICE")+"', \n" +
                                "'"+ gSmap.get("FOREIGNCURRENCY")+"', \n" +
                                "'"+ gSmap.get("EXCHANGERATE")+"', \n" +
                                "'"+ gSmap.get("ANCILLARYAMOUNT")+"', \n" +
                                "'"+ gSmap.get("BIZDATE")+"', \n" +
                                "'"+ gSmap.get("BIZCODE")+"', \n" +
                                "'"+ gSmap.get("OPERATOR")+"', \n" +
                                "'"+ gSmap.get("SJ")+"', \n" +
                                "'"+ gSmap.get("SM")+"', \n" +
                                "'"+ gSmap.get("SETTLEMENT")+"', \n" +
                                "'"+ gSmap.get("SETTLEMENTNUMBER")+"', \n" +
                                "'"+ gSmap.get("APPLICATION")+"', \n" +
                                "'"+ gSmap.get("SETTLEMENTDATE")+"', \n" +
                                "'"+ gSmap.get("CASHPROJECT")+"', \n" +
                                "'"+ gSmap.get("SPECATEID")+"', \n" +
                                "'"+ gSmap.get("BILLNUMBER")+"', \n" +
                                "'"+ DATASTAUS+"', \n" +
                                "'"+ gSmap.get("ISIMPORTED")+"', \n" +
                                "'"+ gSmap.get("FAILREASON")+"', \n" +
                                "'"+ gSmap.get("BATCHNO")+"', \n" +
                                "'"+ REFERENCEID+"', \n" +
                                "'"+ gSmap.get("LYPZID")+"', \n" +
                                "'"+ gSmap.get("FZCODE")+"', \n" +
                                "'"+ gSmap.get("TS")+"',"+
                                "'"+ gSmap.get("ASSID")+"'," +
                                "'"+ gSmap.get("ORGCODE")+"'),";
                        logTS = (String) gSmap.get("TS");
                        voucherCode = (String) gSmap.get("ACCDOCCODE");
                    }
                //去掉拼接的最后一个字符
                insertSQL = insertSQL.substring(0, insertSQL.lastIndexOf(','));
                insertSQL = insertSQL.replace("'null'","NULL") + ";";

            }
            //执行语句
            int update = jdbcTemplate.update(insertSQL);
            //成功
            if (update>0) {
                int loginsert = loginfo.loginfo(jdbcTemplate,methodName, LocalDateTime.now().toString(), "成功", "", "", "", voucherCode, "insertMID", logTS);
                if (loginsert > 0) {
                   // System.out.println("日志写入成功！！");
                } else {
                    System.out.println("日志写入失败！！");
                }
                //失败
            } else {
                //写入日志表
                int loginsert = loginfo.loginfo(jdbcTemplate,methodName, LocalDateTime.now().toString(), "失败", "", "", "", voucherCode, "insertMID", logTS);
                if (loginsert > 0) {
                   // System.out.println("日志写入成功！！");
                } else {
                    System.out.println("日志写入失败！！");
                }
            }
        }
    }
}
